package com.wowangz.cms.systemmanage.city.service;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.city.pojo.City;

public class CityService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(CityService.class);

	/*

	public void delete(String ids) throws Exception {
		if (StringUtils.isEmpty(ids)) {
			return;
		}
		String[] temIds = ids.split(",");
		SqlSessionContainer sessionContainer = new SqlSessionContainer();
		SqlSession sqlSession = (SqlSession) sessionContainer.getSqlSession();

		for (String id : temIds) {
			sqlSession.delete("Currency.deleteCurrency", id);
		}
	}

	*/
	
	/*public void updateAllCurrencyposition(Long currencyposition){
		SqlSessionContainer sessionContainer = new SqlSessionContainer();
		SqlSession sqlSession = (SqlSession) sessionContainer.getSqlSession();
		sqlSession.update("Currency.updateAllCurrencyposition", currencyposition);
	}

	

	public List<Province> query(Province province) throws Exception {
		SqlSessionContainer sessionContainer = new SqlSessionContainer();
		SqlSession sqlSession = (SqlSession) sessionContainer.getSqlSession();
		List<Province> list = sqlSession.selectList("Currency.queryCurrency");
		return list;

	}
	*/
	
	/**
	 * 新增省信息
	 * @param province
	 * @throws Exception
	 */
	public void add(City city) throws ServiceException {
		this.getSqlSession().insert("City.insertCity", city);
	}
	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("City.queryCityCount", map);
		return countNum;
	}

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<City> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<City> list = this.getSqlSession().selectList("City.queryCityPage", map);
		return list;
	}
	
	/**
	 * 验证信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean validationCity(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("City.validationCity", map);
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}
	
	public boolean validationProvince(HashMap<String, Object> map)throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("City.validationProvince", map);
		if(countNum > 0){
			return false;
		}else{
			return true;
		}
	}
	
	public City findCityById(String id) throws ServiceException {
		City city = this.getSqlSession().selectOne("City.findCityById", id);
		return city;
	}
	
	public void update(City city) throws Exception {
		this.getSqlSession().update("City.updateCity", city);
	}
	
	public List<City> findCityByProvinceId(Long id) throws ServiceException {
		List<City> list = this.getSqlSession().selectList("City.findCityByProvinceId", id);
		return list;
	}
	

}
